# -*- coding: utf-8 -*-
# @Author	: brotherbaby
# @Date		: 2023/10/25 10:11
# @Last Modified by:   brotherbaby
# @Last Modified time: 2023/10/25 10:11
# Thanks for your comments!

from sqlalchemy import Column, Integer, BigInteger, VARCHAR, DECIMAL, ForeignKey

from src.consts import ModelName
from src.db_proxy.models.modelbase import ModelBase, ModifyingBehevior
from src.db_proxy.models.person import Person
from src.db_proxy.models.site import Site


class Order(ModelBase, ModifyingBehevior):
    __tablename__ = ModelName.Order.value

    id = Column('id', Integer, primary_key=True, autoincrement=True)
    user_id = Column('user_id', Integer, index=True)
    name = Column('name', VARCHAR(64))  # 每次提交的姓名可能与上次不一致，也就与person中的不一致
    person_id = Column('person_id', Integer, ForeignKey(Person.__tablename__ + '.' + Person.id.name), index=True)
    site_no = Column('site_no', VARCHAR(64), ForeignKey(Site.__tablename__ + '.' + Site.no.name),
                     index=True)  # 站点编号，关联milang_site表
    number = Column('number', Integer)  # 鞋子双数
    commit_time = Column('commit_time', BigInteger, index=True)  # 提交时间戳，毫秒数时间戳
    item_category = Column('item_category', Integer, index=True)  # 物品类型：1鞋子，2衣服。。。
    status = Column('status', Integer, default=0)  # 状态: 0已提交（待工厂收件），7工厂已收件待入厂，1已入厂，2已出厂，3已退回，4配送中，5已完成
    price = Column('price', DECIMAL(11, 2))  # 金额
    payment_channel = Column('payment_channel', Integer, index=True)  # 支付渠道：1抖音团购，2小程序支付
    remark = Column('remark', VARCHAR(256))

    def get_fields(self):
        return {
            "id": self.id,
            "name": self.name,
            "user_id": self.user_id,
            "person_id": self.person_id,
            "site_no": self.site_no,
            "number": self.number,
            "commit_time": self.commit_time,
            "item_category": self.item_category,
            "payment_channel": self.payment_channel,
            "status": self.status,
            "price": self.price,
            "remark": self.remark
        }
